/*
 * @lc app=leetcode.cn id=415 lang=cpp
 * @lcpr version=30204
 *
 * [415] 字符串相加
 */

// @lcpr-template-start
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lcpr-template-end
// @lc code=start
class Solution
{
public:
    // 同第2题链表相加一个逻辑
    string addStrings(string num1, string num2)
    {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        int value1 = 0, value2 = 0, next = 0;
        string addret;
        while (end1 >= 0 || end2 >= 0)
        {
            if (end1 >= 0)
                value1 = num1[end1--] - '0';
            else
                value1 = 0;
            if (end2 >= 0)
                value2 = num2[end2--] - '0';
            else
                value2 = 0;
            int valueret = value1 + value2 + next;
            if (valueret > 9)
            {
                next = 1;
                valueret -= 10;
            }
            else
            {
                next = 0;
            }
            addret += (valueret + '0');
        }
        if (next == 1)
        {
            addret += '1';
        }
        reverse(addret.begin(), addret.end());
        return addret;
    }
};
// @lc code=end

/*
// @lcpr case=start
// "11"\n"123"\n
// @lcpr case=end

// @lcpr case=start
// "456"\n"77"\n
// @lcpr case=end

// @lcpr case=start
// "0"\n"0"\n
// @lcpr case=end

 */
